package com.xfhy.wallpaperdemo.lock;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.xfhy.wallpaperdemo.ActivityUtils;
import com.xfhy.wallpaperdemo.MyApplication;
import com.xfhy.wallpaperdemo.live.pk;

/**
 * @author : xfhy
 * Create time : 2020/10/29 14:28
 * Description :
 */
public class LockScreenReceiver extends BroadcastReceiver implements pk.b {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("xfhy_daemon", "LockScreenReceiver  onReceive: " + intent.getAction());
        if ("android.intent.action.CLOSE_SYSTEM_DIALOGS".equals(intent.getAction())) {
            /*if (RomUtil.isOppo() && Build.VERSION.SDK_INT >= 29) {
                List<ActivityManager.AppTask> appTasks;
                ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
                if (!(activityManager == null || (appTasks = activityManager.getAppTasks()) == null)) {
                    for (ActivityManager.AppTask finishAndRemoveTask : appTasks) {
                        Log.d("xfhy_test","进来了");
                        finishAndRemoveTask.finishAndRemoveTask();
                    }
                }
            }*/
            if (MyApplication.sActivity != null) {
                MyApplication.sActivity.finish();
            }
            return;
        }
        g();
    }

    @Override
    public void onScreenStatusChanged(boolean z2) {
        //g();
        Log.d("xfhy_daemon", "当前屏幕状态   onScreenStatusChanged:" + z2);
    }

    private void g() {
        //先展示一个通知
        NotifyUtil.showPermanentNotification();
        //开启锁屏页
        b(new Intent(MyApplication.sContext, PresentLockscreenActivity.class));
    }

    private boolean b(Intent intent) {
        ActivityUtils.hookJumpActivity(MyApplication.sContext, intent);
        return true;
    }

}

